bool isDelimiters (char ch)
{
	static string deliemeters(" ;.?");
	if ( std::string::npos == deliemeters.find(ch) ) 
		return false;
	return true;
}

unsigned int countWords(string string)
{
    if (string.empty() == true)
   	 return 0;
    bool isInWord = false;
    unsigned int wordCount = 0;
    int len = string.length();    
    char ch =0;
    for(int i = 0 ; i <= len; ++i) // intionally <=
    {
   	 if (i<len)
   	 {
   		 ch =  string.at(i);
   	 }
   	 else // no trailing space ...
   	 {
   		 ch = ' ';   	//assigning blank splace to ch	 
   	 }
   	 bool isDelimitersChar  = isDelimiters(ch);
   	 if( false == isDelimitersChar  && false == isInWord )
   	 { // means word has just began and this is the first character.
   		 isInWord = true;
   	 }
   	 else if (true == isDelimitersChar  && true == isInWord)
   	 { //word has ended
   		 isInWord = false;
   		 ++wordCount;
   	 }
   	 else if ( false == isDelimitersChar  && true == isInWord )
   	 {
   		 // Delimiters  is not seen , we are still in word ... keep going
   	 }
   	 else if ( true  == isDelimitersChar  && false == isInWord )
   	 {
   		 // we are not in word so it really doesn't matter...
   		 // this could be multiple spaces( or other Delimiters) between two words
   	 }    
    }
    return wordCount;
}

int main()
{
	string str("Count number of  words in this");
	cout<<"Number of words :"<<countWords(str)<<endl;
        return 0;
}